<?php
class ArticleService
{
	public function getArticleCate($type='',$num = 0)
	{
		$list = array();
		
		if($type != '')
			$where = ' AND type = '.intval($type);
			
		if($num > 0)
			$limit = ' LIMIT 0,'.$num;
		
		$res = DB::query('SELECT id,name  
						FROM '.DB::table('article_cate').'  
						WHERE status = 1 '.$where.' ORDER BY sort ASC,id DESC'.$limit);
		
		while($data = DB::fetch($res))
		{
			$list[] = $data;
		}

		return $list;
	}
	
	public function getArticleList($cate = 0,$num = 0)
	{
		$list = array();
		
		if($cate > 0)
			$where = ' AND cate_id = '.$cate;
			
		if($num > 0)
			$limit = ' LIMIT 0,'.$num;
		
		$res = DB::query('SELECT id,name,ref_link,preview,brief   
						FROM '.DB::table('article').' 
						WHERE status = 1 '.$where.' ORDER BY sort ASC,id DESC'.$limit);
		
		while($data = DB::fetch($res))
		{
			if(empty($data['ref_link']))
				$data['url'] = U('article/show',array('id'=>$data['id']));
			else
				$data['url'] = $data['ref_link'];
			
			$list[] = $data;
		}

		return $list;
	}
}
?>